<?php
##############################################
#
#   抽奖规则
# @ Time : 2017-1-8 - 下午9:20:27
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Admin\Model;


class RuleprizeModel extends AdminBaseModel{
	/*抽奖规则表 */
	protected $tableName = 'lottery_rules';	
	
	/**
	 * 获取所有规则
	 */
	public function getRule($rule_name){
		if($rule_name){
			$map['rule_name'] = array('like','%'.$rule_name.'%');
		}
		$count = $this -> where($map) -> count();// 查询满足要求的总记录数
	    $Page = new \Think\Page($count, 10);
	    $show = $Page -> show();
		$result = $this -> where($map) -> order('r_id desc') -> limit($Page->firstRow.','.$Page->listRows) -> select();
		return array($result, $show);
	}
	
	//获取活动表数据
	public function getActivity(){
		return $this -> table('mt_activity') -> select();
	}

	public function getxunvPrize(){
		return $this -> table("mt_prize") -> where("prize_type = 1") -> select();
	}

	public function getshiwuPrize(){
		return $this -> table("mt_prize") -> where("prize_type = 2") -> select();
	}

	public function addRule($data){
		return $this -> add($data);
	}

	public function getPirzeName($p_id){
		return $this -> table('mt_prize') -> where("p_id = $p_id") -> getField('prize_name');
	}

	public function getActivityName($a_id){
		return $this -> table('mt_activity') -> where("id = $a_id") -> getField('activity_name');
	}

	public function addPrizeAppend($data){
		if(!$data['append_id']){
			return $this -> table('mt_prize_append') -> add($data);
		}else{
			return $this -> table('mt_prize_append') -> where("append_id = {$data['append_id']}") -> save($data);
		}
	}

	public function getPrizeAppend($r_id){
		return $this -> table('mt_prize_append') -> where("r_id = $r_id") -> find();
	}

	public function updateRule($r_id){
		return $this -> where("r_id = $r_id") -> find();
	}

	public function updateRuleFind($data){
		return $this -> where("r_id = {$data['r_id']}") -> save($data);
	}

	public function deleteRule($r_id){
		return $this -> where("r_id = $r_id") -> delete();
	}
	
}